import type { spotItem } from '@/types/eat'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useDeviceStore = defineStore(
  'device',
  () => {
    /**
     * * 设备信息
     */
    const deviceInfo = ref<spotItem>()

    /**
     * * 保存设备信息
     * @param val
     */
    const setDeviceInfo = (val: spotItem) => {
      deviceInfo.value = val
    }

    /**
     * * 清理设备信息
     */
    const clearDeviceInfo = () => {
      deviceInfo.value = undefined
      uni.removeStorageSync('device')
    }
    return {
      deviceInfo,
      setDeviceInfo,
      clearDeviceInfo,
    }
  },
  {
    // 数据持久化
    persist: {
      storage: {
        setItem(key, value) {
          uni.setStorageSync(key, value)
        },
        getItem(key) {
          return uni.getStorageSync(key)
        },
      },
    },
  },
)
